package com.hxh.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.hxh.entity.ProjectTableFiledConfig;
import com.hxh.entity.input.ProjectTableFiledConfigInput;
import com.hxh.entity.output.ApiResult;
import com.hxh.service.ProjectTableFiledConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/projectTableFiledConfig")
@Slf4j
public class ProjectTableFiledConfigController {
    @Autowired ProjectTableFiledConfigService projectTableFiledConfigService;

    //获取项目表字段映射配置分页
    @RequestMapping(value = "/listPage", produces = "application/json;charset=utf-8")
    public ApiResult listPage(ProjectTableFiledConfigInput pojo) {
        Page<ProjectTableFiledConfig> page = new Page<>(pojo.getCurrent(), pojo.getPageSize());
        projectTableFiledConfigService.listPage(page, pojo);
        return ApiResult.ok("获取项目表字段映射配置分页成功", page);
    }

    //新增项目表字段映射配置
    @PostMapping(value = "add")
    public ApiResult add(ProjectTableFiledConfig projectTableFiledConfig) {
        boolean flag = projectTableFiledConfigService.insert(projectTableFiledConfig);
        if (flag) {
            return ApiResult.ok("保存成功");
        }
        return ApiResult.fail("保存失败");
    }

    //修改项目表字段映射配置
    @PostMapping(value = "update")
    public ApiResult update(ProjectTableFiledConfig projectTableFiledConfig) {
        boolean flag = projectTableFiledConfigService.update(projectTableFiledConfig);
        if (flag) {
            return ApiResult.ok("更新成功");
        } else {
            return ApiResult.fail("更新失败");
        }
    }

    //删除项目表字段映射配置
    @PostMapping(value = "delete")
    public ApiResult deleteById(@RequestParam Integer id ) {
        boolean flag = projectTableFiledConfigService.deleteById(id );
        if (flag) {
            return ApiResult.ok("删除成功");
        } else {
            return ApiResult.fail("删除失败");
        }
    }

}
